import { Component, OnInit } from '@angular/core';

declare let T: any

@Component({
  selector: 'app-t-map',
  templateUrl: './t-map.component.html',
  styleUrls: ['./t-map.component.scss']
})
export class TMapComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
    this.initMap()
  }

  map: any = null
  zoom = 12;
  initMap() {
    console.log(T)
    this.map = new T.Map('mapDiv')



    // this.map.centerAndZoom(new T.LngLat(116.40769, 39.89945), this.zoom);

    this.getCurrentLocation()
  }

  // 获取当前位置
  getCurrentLocation() {
    // 获取当前位置
    // const lo = new T.Geolocation()
    // console.log(lo.getStatus())
    const _this = this
    const fn = function(e: any) {
      alert("获取定位坐标：" + e.lnglat.lat + "," + e.lnglat.lng)
  
      //详细地址，逆地理编码
      var geocoder = new T.Geocoder();
      geocoder.getLocation(e.lnglat, _this.searchResult);
    }

    var lo = new T.Geolocation();
    lo.getCurrentPosition(fn);
    const sta = lo.getStatus()
    console.log(sta)
  }
  fn(e: any) {
    alert("获取定位坐标：" + e.lnglat.lat + "," + e.lnglat.lng)

    //详细地址，逆地理编码
    var geocoder = new T.Geocoder();
    geocoder.getLocation(e.lnglat, this.searchResult);
  }

  searchResult(result: any) {
    console.log(result)
  }

}
